package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Request;
import com.ruoyi.system.service.IRequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户请求Controller
 * 
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/request")
public class RequestController extends BaseController
{
    @Autowired
    private IRequestService requestService;

    /**
     * 查询客户请求列表
     */
    @PreAuthorize("@ss.hasPermi('system:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(Request request)
    {
        startPage();
        List<Request> list = requestService.selectRequestList(request);
        return getDataTable(list);
    }

    /**
     * 导出客户请求列表
     */
    @PreAuthorize("@ss.hasPermi('system:request:export')")
    @Log(title = "客户请求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Request request)
    {
        List<Request> list = requestService.selectRequestList(request);
        ExcelUtil<Request> util = new ExcelUtil<Request>(Request.class);
        util.exportExcel(response, list, "客户请求数据");
    }

    /**
     * 获取客户请求详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:request:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(requestService.selectRequestByRequestId(requestId));
    }

    /**
     * 新增客户请求
     */
    @PreAuthorize("@ss.hasPermi('system:request:add')")
    @Log(title = "客户请求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Request request)
    {
        return toAjax(requestService.insertRequest(request));
    }

    /**
     * 修改客户请求
     */
    @PreAuthorize("@ss.hasPermi('system:request:edit')")
    @Log(title = "客户请求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Request request)
    {
        return toAjax(requestService.updateRequest(request));
    }

    /**
     * 删除客户请求
     */
    @PreAuthorize("@ss.hasPermi('system:request:remove')")
    @Log(title = "客户请求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(requestService.deleteRequestByRequestIds(requestIds));
    }
}
